<extend name="./base" />
<block name="body">
<style>
    .is_reducesalary_contant{
        margin-top:17%;
    }
    .is_reducesalary_contant .modal-content{
        padding-bottom: 20px;
    }
</style>
<table class="table">
    <caption>老师列表<a href="/Home/Index/downSalaryXls" style="float: right;">下载工资</a></caption>
    <thead>
    <tr>
        <th>真实姓名</th>
        <!--th>擅长学科</th-->
        <th>擅长年级</th>
        <th>学校</th>
        <th>电话号码</th>
        <th>支付宝</th>
        <!--<th>地点</th>-->
        <th>操作</th>
        <th>审核</th>
        <th>认证</th>
        <th>注册时间</th>
        <!--<th>首页展示</th>-->
        <th>工资金额</th>
        <th>发工资</th>
    </tr>
    </thead>
    <tbody>
    <?php  if($data){?>
    <foreach name="data" item="vo">
        <tr>
            <td>{$vo.relname}</td>
            <!--td>{$vo.lesson}</td-->
            <td>{$vo.grade}</td>
            <td>{$vo.school}</td>
            <td>{$vo.phone}</td>
            <td>{$vo.zhifubao}</td>
            <!--<td>{$vo.address}</td>-->
            <td><a href="__ROOT__/index.php/Admin/Teacher/detail/id/{$vo.user_id}">详情</a></td>
            <td>
                <select class="cl_status" data-id="{$vo.new_user_id}" >
                    <option value="0" <if condition="($vo.status eq 0) "> selected  </if> >待审核</option>
                    <option value="1" <if condition="($vo.status eq 1) "> selected  </if>>已审核</option>
                    <option value="2" <if condition="($vo.status eq 2) "> selected  </if>>审核失败</option>
                </select>
            </td>
            <td>
                <select class="cl_certified" data-id="{$vo.new_user_id}">
                    <option value="0"<if condition="($vo.is_certified eq 0) "> selected  </if> >待认证</option>
                    <option value="1"<if condition="($vo.is_certified eq 1) "> selected  </if>>已认证</option>
                    <option value="2" <if condition="($vo.is_certified eq 2) "> selected  </if>>认证失败</option>
                </select>
            </td>
            <td>
                {$vo.addtime}
            </td>
            <td>
                {$vo.salary}
            </td>
            <td>
                <input type="text" class="reducesalary" name="reducesalary" value="">
                <input type="button" class="reducesalary_btn" value="扣费">
                <input type="hidden" class="teacher_id" value="{$vo.user_id}">
            </td>
            <!--<td>-->
            <!--<select class="is_star" data-id="{$vo.new_user_id}">-->
            <!--<option value="0"<if condition="($vo.star eq 0) "> selected  </if> >否</option>-->
            <!--<option value="1"<if condition="($vo.star eq 1) "> selected  </if>>是</option>-->
            <!--</select>-->
            <!--</td>-->

        </tr>
    </foreach>
    <?php }else{?>
    <tr><td>暂无数据</td></tr>
    <?php }?>
    </tbody>
</table>
<div class="modal fade is_reducesalary">
    <div class="modal-dialog text-center is_reducesalary_contant">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close change_cancel" data-dismiss="changePanel" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title">是否确认扣除工资？</h4>
            </div>
            <form action="#" id="changeForm" method="post">
                <a href="javascript:;" class="btn btn-lg is_reducesalary_btn" data-dismiss="modal" type="submit">确认扣除</a>
                <a href="javascript:;" class="btn btn-lg change_cancel" >取消</a>
            </form>
        </div>
    </div>
</div>
<div>
    {$render}
</div>

<script type="text/javascript">
    $(".cl_certified").change(function(){
        var this_id = $(this).data("id");
        var this_status=$(this).val();
        var this_type = 1;
        if ( confirm('你确定操作吗？') ) {
            $.ajax({
                type: "post",
                url: "__ROOT__/index.php/Admin/Teacher/verify",
                dataType: 'json',
                data:{
                    user_id:this_id,
                    is_certified:this_status,
                    type:this_type
                },
                success: function(result) {
                    if ( result.flag == 1) {
                        alert('操作成功!');
                    } else{
                        alert('操作失败!');
                    }
                }
            })
        }else{
            location.reload();
        };
    });
</script>

<script type="text/javascript">
    $(".cl_status").change(function(){
        var this_id = $(this).data("id");
        var this_status=$(this).val();
        var this_type = 2;
        if ( confirm('你确定操作吗？') ) {
            $.ajax({
                type: "post",
                url: "__ROOT__/index.php/Admin/Teacher/verify",
                dataType: 'json',
                data:{
                    user_id:this_id,
                    status:this_status,
                    type:this_type
                },
                success: function(result) {
                    if ( result.flag == 1) {
                        alert('操作成功!');
                    } else{
                        alert('操作失败!');
                    }
                }
            })
        }else{
            location.reload();
        };
    });
</script>


<script type="text/javascript">
    $(".is_star").change(function(){
        var this_id = $(this).data("id");
        var this_status=$(this).val();
        alert(this_status);
        if ( confirm('你确定操作吗？') ) {
            $.ajax({
                type: "post",
                url: "__ROOT__/index.php/Admin/Teacher/star",
                dataType: 'json',
                data:{
                    user_id:this_id,
                    star:this_status,
                },
                success: function(result) {
                    if ( result.flag == 1) {
                        alert('操作成功!');
                    } else{
                        alert('操作失败!');
                    }
                }
            })
        }
    });
</script>
<script>
    var $reducesalary;
    var $teacher_id;
    $('.reducesalary_btn').on('click',function(){
        $reducesalary=$(this).prevAll('.reducesalary').val();
        $teacher_id=$(this).nextAll('.teacher_id').val();
        $('.is_reducesalary').show().addClass('in');
    });
    $('.change_cancel').click(function(){
        $('.is_reducesalary').hide().removeClass('in');
    });
    $('.is_reducesalary_btn').on('click',function(){
        $.ajax({
            type: "post",
            url: "/Admin/teacher/paySalary",
            dataType: 'json',
            data:{
                teacher_id:$teacher_id,
                reducesalary:$reducesalary
            },
            success: function(data) {
                if ( data.error == 0) {
                    $('#changePanel').hide().removeClass('in');
                    location.reload();
                } else{
                    alert(data.msg);
                }
            }
        });
    });
</script>
</block>